#include "widget.h"
#include "ui_widget.h"

#include<QKeyEvent>
#include<QDebug>
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    setMouseTracking(true);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::keyPressEvent(QKeyEvent *event)
{
    if(event->modifiers()==Qt::ControlModifier) //按下了control按键
    {
        if(event->key()==Qt::Key_A)
        {
            qDebug()<<"按下了按键ctrl+A";
        }
    }
}

void Widget::mousePressEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton)
    {
        qDebug()<<"左击";
    }
    if(event->button()==Qt::RightButton)
    {
        qDebug()<<"右击";
    }
    if(event->button()==Qt::MidButton)
    {
        qDebug()<<"鼠标滚轮";
    }
}

void Widget::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton)
    {
        qDebug()<<"左击释放";
    }
    if(event->button()==Qt::RightButton)
    {
        qDebug()<<"右击释放";
    }
    if(event->button()==Qt::MidButton)
    {
        qDebug()<<"鼠标滚轮释放";
    }
}

void Widget::mouseDoubleClickEvent(QMouseEvent *event)
{
    if(event->button()==Qt::LeftButton)
    {
        qDebug()<<"鼠标左击两次";
    }
    if(event->button()==Qt::RightButton)
    {
        qDebug()<<"鼠标右击两次";
    }
    if(event->button()==Qt::MidButton)
    {
        qDebug()<<"鼠标滚轮点击两次";
    }
}

void Widget::mouseMoveEvent(QMouseEvent *event)
{
    qDebug()<<"["<<event->x()<<","<<event->y()<<"]";
}

void Widget::wheelEvent(QWheelEvent *event)
{
    //滚轮滑动的距离delta
    static int x=0;
    x+=event->delta();
    if(event->delta()>0)
    {
        qDebug()<<"滚轮向前滑动"<<x;
    }
    else
    {
        qDebug()<<"滚轮向后滑动"<<x;
    }
}



